package com.example.myapplication;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;



import java.util.List;

public class PhotoAdapter extends ArrayAdapter<Photo> {

    private int resourceId;
    public PhotoAdapter(Context context, int textViewResourceId, List<Photo>objects)
    {
        super(context,textViewResourceId,objects);
        resourceId=textViewResourceId;
    }


    @Override
    public View getView(int position,  View convertView,  ViewGroup parent) {
        Photo photo=getItem(position);
        View view;
        if (convertView==null)
        {
           view= LayoutInflater.from(getContext()).inflate(resourceId,parent,false);
        }
        else
        {
            view=convertView;
        }
        ImageView photoImage=(ImageView)view.findViewById(R.id.photo_image);
        photoImage.setImageResource(photo.getImageId());
        return view;
    }
}
